# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=pg-safeupdate
pkgver=1.4
pkgrel=3
pkgdesc="A simple extension to PostgreSQL that requires criteria for UPDATE and DELETE"
arch=('loong64' 'x86_64')
url="https://github.com/eradman/pg-safeupdate"
license=('ISC')
depends=('postgresql')
checkdepends=('pifpaf' 'ruby')
source=("https://github.com/eradman/pg-safeupdate/archive/$pkgver/$pkgname-$pkgver.tar.gz")
sha512sums=('a2aed61f995df5e6bd182213abcd95541ceafa07756c3fa5f012f910643c00c0ada2c1ea04a4d6c70c7e0bacd23ba022aca03c7e88dd7ad05bf816b4c1a36037')

build() {
  cd $pkgname-$pkgver
  make safeupdate.so
}

check() {
  cd $pkgname-$pkgver
  sed -i 's|^\$url = .*$|\$url = ENV["PIFPAF_URL"]|' test.rb
  eval $(pifpaf run postgresql)
  # No idea how to run it against the built extension
  # psql -c 'CREATE EXTENSION safeupdate'
  # ruby test.rb
  pifpaf_stop
}

package() {
  cd $pkgname-$pkgver
  install -Dm755 safeupdate.so -t "$pkgdir"/usr/lib/postgresql/
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/license/$pkgname/
}
# vim:set ts=2 sw=2 et:
